/***********************通讯协议文件************************/
#ifndef _RFPROTOCOL_H
#define _RFPROTOCOL_H

/*******************设备类型说明********************
0 -- base;
1 -- tag;
2 -- bottle;
f -- server;
***********************************************/
#pragma pack(push)
#pragma pack(1)

typedef enum {
    BOTTLTOBASE = 0x20,
    SERVERTOBASE = 0xF0,
    TAGTOBASE = 0x10,

    BASETOBOTTL = 0x02,
    BASETOTAG = 0x01,
    BASETOSERVER = 0x0F,

    SENDSEARCHNET = 0x40,
    BACKSEARCHNET = 0x04

} agreementTypeEDef;

typedef enum {
    TAGACTION_BEND = 0x00,
    TAGACTION_GET_UP = 0x01,
    TAGACTION_LOW_POWER = 0x02,
    TAGACTION_WASH_HANDS = 0x03,
    TAGACTION_ASK = 0x04,
    TAGACTION_TEST = 0x05,
    LIQUIDACTION_DEFAULT = 0x07,
    TAGACTION_INROOM = 0x08,
    TAGACTION_STANDSTILL = 0x09
} deviceActionEdef;

typedef enum {
    HEALTHEY = 0x00,
    UNHEALTHEY = 0x01,
    NOUSEFUL = 0X02
} tagStateDef;

typedef enum {
    TAGCMD_NOALARM = 0x00,
    TAGCMD_ALARM = 0x01,
    TAGCMD_NOUSE = 0x02,
    TAGCMD_RESETSYS = 0xAA
} tagCmdDef;

typedef enum {
    CCBOTTL = 0x02,
    CCTAG = 0x01,
    CCBASE = 0x00
} CCDeviceEDef;

typedef struct __sensorDataDef { //结构体定义
    uint16_t angle[3];
    uint16_t acc[3];
    uint16_t magn[3];
} sensorDataDef;

typedef struct __baseToServerCmdDef { //结构体定义
    uint8_t aucPreData[2];
    uint8_t ucDatalen;
    uint8_t ucTransmitID;//add transmit ID;base to serve
    uint16_t usBaseAddr;
    agreementTypeEDef tAgreementType;
    uint16_t usDevAddr;
    CCDeviceEDef tDeviceType;
    deviceActionEdef tAction;
    uint8_t ucBatVal;
    tagStateDef eTagState;
    uint8_t ucSum;
} baseToServerCmdDef;

typedef struct __serverToBaseCmdDef { //结构体定义
    uint8_t aucPreData[2];
    uint8_t ucDatalen;
    uint16_t usBaseAddr;
    agreementTypeEDef tAgreementType;
    uint16_t usDevAddr;
    CCDeviceEDef tDeviceType;
    tagCmdDef ucCmd;
    uint8_t ucSum;
} serverToBaseCmdDef;

typedef struct __baseToSlaveCmdDataDef {
    uint8_t ucTransmitID;
    uint16_t usDevAddr;
    agreementTypeEDef tAgreementType;
    uint16_t usBaseAddr;
    tagCmdDef ucCmd;
    uint8_t ucSum;
} baseToSlaveCmdDataDef;

typedef struct __baseToSlaveCmdDef { //结构体定义
    uint8_t ucDatalen;
    baseToSlaveCmdDataDef tB2SlCmdData;
} baseToSlaveCmdDef;

typedef struct __slaveToBaseCmdDataDef {
    uint8_t ucTransmitID;
    uint16_t usBaseAddr;
    agreementTypeEDef tAgreementType;
    uint16_t usDevAddr;
    deviceActionEdef tAction;
    uint8_t ucBatVal;
    tagStateDef ucTagState;
    uint8_t ucSum;
} slaveToBaseCmdDataDef;

typedef struct __slaveToBaseCmdDef { //结构体定义
    uint8_t ucDatalen;
    slaveToBaseCmdDataDef tSl2BCmdData;
} slaveToBaseCmdDef;

typedef struct __rfMetricCmdDef {
    uint8_t ucData[2];//ucData[0] rssi; ucData[1] CRC and LQI
    int8_t cRssi;
} rfMetricCmdDef;

#pragma pack(pop) //恢复到原先值


#endif
/*************************************************************/
